package cn.interestinghop.dao;

import java.sql.*;

public class BaseDao<C> {
    private static String driverClass="com.mysql.cj.jdbc.Driver";
    private static String url="jdbc:mysql://localhost:3306/interesting_shop_db?serverTimezone=GMT-8";
    private static String userName="root";
    private static String password="root";
    private Connection conn=null;

    //获得连接
    public Connection getConnection(){
        try {
            //1、加载驱动
            Class.forName(driverClass);
            //2、获得连接
            conn=DriverManager.getConnection(url,userName,password);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return conn;
    }

    //关闭连接
    public void closeAll(Connection conn,Statement st,ResultSet rs){
        try {
            if(conn!=null)
                conn.close();
            if(st!=null)
                st.close();
            if(rs!=null)
                rs.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
